package com.mariusz.panels;

import java.awt.Graphics;
import java.awt.Image;

import java.io.IOException;
import java.io.InputStream;


import javax.imageio.ImageIO;
import javax.swing.JPanel;

public class ResourceImagePanel extends JPanel {

	Image img;

	public ResourceImagePanel(String fileName) {
		super();
		try {
			InputStream stream = ClassLoader.getSystemResourceAsStream("com/mariusz/resources/"+fileName);
			
			img = loadImage(stream);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	
	}

	public void paintComponent(Graphics g) {
		super.paintComponent(g);
		if (img != null) {
			g.drawImage(img, 0, 0, this);
		}
	}

	public Image loadImage(InputStream stream) throws IOException {
		
		Image image = ImageIO.read(stream);
		return image;

	}

}
